package com.zf.wms.nservice.controller;

import com.zf.wms.nservice.client.RoleClient;
import com.zf.wms.nservice.dto.RoleDto;
import com.zf.wms.nservice.utils.ResultMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Author：sl
 * Date：2019-11-04 9:08
 * Description：<描述>
 */


@Api(tags = "角色管理")
@RestController
@RequestMapping(value = "/role")
public class RoleManageController {

    @Autowired
    private RoleClient roleClient;

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("新增用户角色")
    public ResultMap add(@RequestParam("roleName") String roleName) {
        return roleClient.addRole(roleName);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("查询用户角色列表")
    public ResultMap getList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "1") Integer pageSize) {
        return roleClient.getRoleList(pageNum,pageSize);
    }


    @RequestMapping(value = "/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("删除用户角色")
    public ResultMap remove(@RequestParam(value = "roleId") Long roleId) {

        return roleClient.removeRoleById(roleId);
    }


    @RequestMapping(value = "/modify", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("修改用户角色")
    public ResultMap modify(@RequestBody()RoleDto roleDto) {

        return roleClient.modifyRoleById(roleDto);
    }

    @RequestMapping(value = "/getListByRoleName", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("根据角色名模糊查询角色")
    public ResultMap getListByRoleName(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "1") Integer pageSize,@RequestParam(value = "roleName") String roleName) {



        return roleClient.getListByRoleName(pageNum,pageSize,roleName);
    }

}
